package com.colorfruit.listener;

import com.colorfruit.util.SendWxMessageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceCanceledEvent;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRegisteredEvent;
import org.springframework.cloud.netflix.eureka.server.event.EurekaServerStartedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @Date: 2018/10/17
 */
@Component
public class EurekaStateEventListener {

	private Logger log = LoggerFactory.getLogger(EurekaStateEventListener.class);

	@EventListener
	public void listen(EurekaInstanceCanceledEvent eurekaInstanceCanceledEvent) {
		String appName = eurekaInstanceCanceledEvent.getAppName();
		log.info("-----------------------------------------------------");
		log.info(appName + "已下线");
		log.info("-----------------------------------------------------");
//		SendWxMessageUtil.sendMessage(appName, "oQx9E0TnXI85cIaa5a0d76l9W2GQ"); // 齐朴
//		SendWxMessageUtil.sendMessage(appName, "oQx9E0XPG7hsxVWPOgtts8fuCJfo"); // 琦哥
//		SendWxMessageUtil.sendMessage(appName, "oQx9E0dmpIoiIUAmY5EhaJIGvZXo"); // 柏平
//		SendWxMessageUtil.sendMessage(appName, "oQx9E0dbELoWqe-Fw50kraTav68o"); // 小熊
		SendWxMessageUtil.sendMessage(appName, "oQx9E0X5rOv0uR5rVr8GOUgUJ8uA"); // 陈浩
}

	@EventListener
	public void listen(EurekaInstanceRegisteredEvent eurekaInstanceRegisteredEvent) {
		log.info("-----------------------------------------------------");
		log.info(eurekaInstanceRegisteredEvent.getInstanceInfo().getAppName() + "已上线");
		log.info("-----------------------------------------------------");
	}

	@EventListener
	public void listen(EurekaServerStartedEvent eurekaServerStartedEvent) {
		log.info("-----------------------------------------------------");
		log.info(eurekaServerStartedEvent.getSource().toString() + "已启动");
		log.info("-----------------------------------------------------");
	}

}
